package com.wonders.frame.repository;

import com.wonders.frame.entity.AuthLog;
import com.wonders.frame.repository.core.CoreRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author qiu
 * @date 2020-05-13 12:24
 */
@Repository
public interface AuthLogRepository extends CoreRepository<AuthLog> {

    @Transactional
    @Modifying
   // @Query(nativeQuery = true,value ="delete from auth_log where execute_date between ?1 and ?2 ")
    @Query(nativeQuery = true,value = "delete from auth_log where if(?1 !='null',execute_date>=?1,1=1) and if(?2 !='null',execute_date<=?2,1=1)")
    void deleteByBEDate(String beginDate,String endDate);

    @Transactional
    @Modifying
    void deleteByExecuteDateLessThanEqual(Date date);

    @Transactional
    @Modifying
    void deleteByExecuteDateGreaterThanEqual(Date date);

    @Transactional
    @Modifying
    void deleteByExecuteDateBetween(Date startDate,Date endDate);
}
